package com.davidx.tool.contoller;

import cn.hutool.extra.mail.MailUtil;
import com.davidx.tool.wrapper.WrapMapper;
import com.davidx.tool.wrapper.Wrapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Davidx
 * @email 75736409@qq.com
 * @date 2018/11/14
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/api/email", method = {RequestMethod.POST, RequestMethod.GET})
public class EmailCtrl {


    /**
     * 发送简单的邮件
     *
     * @param to      收件人
     * @param subject 标题
     * @param content 正文
     * @return
     */
    @RequestMapping(value = "/sendSimpleEmail")
    public Wrapper sendSimpleEmail(String to, String subject, String content) {
        MailUtil.sendText(to, subject, content);
        return WrapMapper.ok();
    }

    /**
     * 发送Html的邮件
     *
     * @param to      收件人
     * @param subject 标题
     * @param content 正文
     * @return
     */
    @RequestMapping(value = "/sendHtmlEmail")
    public Wrapper sendHtmlEmail(String to, String subject, String content) {
        MailUtil.sendHtml(to, subject, content);
        return WrapMapper.ok();
    }

}
